package com.wyp168.socket.tcp.upload02;

import com.wyp168.socket.utils.StreamUtils;

import java.io.*;
import java.net.InetAddress;
import java.net.Socket;
import java.net.SocketAddress;
import java.net.UnknownHostException;

/**
 * @ClassName Client
 * @Title TODO
 * @Description TODO
 * @Author wyp168
 * @Date 2022/10/29 12:02
 */
public class Client {
    public static void main(String[] args) throws Exception {
        Socket socket = new Socket(InetAddress.getByName("192.168.0.103"), 18082);

        String fileName = "wyp168.jpg";
        socket.getOutputStream().write(fileName.getBytes());
        socket.shutdownOutput();

        BufferedInputStream bis = new BufferedInputStream(socket.getInputStream());
        byte[] fileBytes = StreamUtils.streamToByteArray(bis);
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("/Users/wangyuanpeng/com/downloadTest/" + fileName));
        bos.write(fileBytes);
        bos.flush();

        //关闭资源
        bos.close();
        bis.close();
        socket.close();
    }
}
